//数组去重
function quchong(arr){
	Array.prototype.unique2 = function(){
	 this.sort(); //先排序
	 var res = [this[0]];
	 for(var i = 1; i < this.length; i++){
	  if(this[i] !== res[res.length - 1]){
	   res.push(this[i]);
	  }
	 }
	 return res;
	}
	return arr.unique2();
}

//获取cookie
function getCookie(con){
	var cookies=document.cookie;
	var arr=cookies.split("; ");
	for(var i=0;i<arr.length;i++){
		var arr2=arr[i].split("=");	
		if(arr2[0]==con){
			return arr2[1];
		}
	}
	return false;
}
//保存cookie
function saveCookie(name,value,day){
	var date1=new Date();
	date1.setDate(date1.getDate()+day);
	var str = name+"="+value+";expires="+date1;
	document.cookie=str;
}
//移除cookie
function removeCookie(con){
	saveCookie(con,"",-1);
}
//滚轮
function mouseWheel(obj, fn) {
	var Firefox = window.navigator.userAgent.indexOf("Firefox");
	if(Firefox != -1) {
		obj.addEventListener("DOMMouseScroll", wheel, false);
	} else {
		obj.onmousewheel = wheel;
	}

	function wheel(ev) {
		var evObj = ev || window.event;
		var down = true;
		if(ev.detail) {
			down = ev.detail < 0;
		} else {
			down = ev.wheelDelta > 0;
		}
		//回调函数,把值回传给调用处
		fn(down,evObj);
		//取消默认事件
		if(ev.preventDefault()){
			ev.preventDefault();
		}
		return false;
	}
}
//冒泡排序:
function maopao(arr) {
     for(var i = 0; i < arr.length - 1; i++) {
          for(var j = 0; j < arr.length - i - 1; j++) {
               if(arr[j] > arr[j + 1]) {
                    var temp = arr[j];
                     arr[j] = arr[j + 1];
                     arr[j + 1] = temp;
                }
           }
     }
     return arr;
}
//随机数函数:
function rand(a,b){
return Math.floor(Math.random( )*(b-a+1)+a);
}
//圆碰撞检测
function checkARC(arc1, arc2) {
	//设置临界条件
	var disR = arc1.r + arc2.r;
	//取2个圆心距离的大小
	var chaX = Math.abs(arc1.x - arc2.x);
	var chaY = Math.abs(arc1.y - arc2.y);
	if(chaX * chaX + chaY * chaY <= disR * disR) {
		console.log("撞上了");
	}
}
//方块碰撞检测
function checkRECT(obj1, obj2) {
	//先算临界值
	//横向临界值
	var disX = obj1.w / 2 + (obj2.w / 2);
	//纵向临界值
	var disY = obj1.h / 2 + (obj2.h / 2);
	//计算2个矩形对象中心的距离
	var centerX = Math.abs((obj1.x + obj1.w / 2) - (obj2.x + (obj2.w / 2)));
	var centerY = Math.abs((obj1.y + obj1.h / 2) - (obj2.y + (obj2.h / 2)));

	//判断
	if(centerX < disX && centerY < disY) {
		return true;
	} else {
		return false;
	}
}